package com.cjm.one.goods.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.goods.service.CouponInfoService;
import com.cjm.one.model.coupon.dto.CouponInfoDto;
import com.cjm.one.model.coupon.entity.CouponInfo;
import com.cjm.one.model.coupon.vo.CouponInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "4-优惠券信息", description = "优惠券信息")
@RequestMapping("/admin/coupon/info")
public class CouponInfoController {
    @Resource
    private CouponInfoService couponInfoService;
    @GetMapping("/list")
    @Operation(summary = "优惠券列表")
    public Result<Page<CouponInfo>> list(@RequestParam(name = "current",defaultValue = "1") Long current,
                                         @RequestParam(name = "size",defaultValue = "10") Long size,
                                         @RequestParam(name = "rangeType",required = false) Integer rangeType,
                                         @RequestParam(name = "couponName",required = false) String couponName,
                                         @RequestParam(name = "status",required = false) Integer status) {
        return Result.ok(couponInfoService.getCouponInfoPage(current,size,rangeType,couponName,status));
    }

    @PostMapping
    @Operation(summary = "添加优惠券")
    public Result<Boolean> add(@RequestBody CouponInfoDto couponInfoDto) {

        return Result.ok(couponInfoService.SaveCoupon(couponInfoDto));
    }

    @PutMapping
    @Operation(summary = "修改优惠券")
    public Result<Boolean> update(@RequestBody CouponInfoDto couponInfoDto) {
        return Result.ok(couponInfoService.UpdateCoupon(couponInfoDto));

    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除优惠券")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.ok(couponInfoService.DeleteCoupon(id));
    }
    @GetMapping("/{id}")
    @Operation(summary = "获取优惠券详情")
    public Result<CouponInfoVo> get(@PathVariable Long id) {
        return Result.ok(couponInfoService.getCouponById(id));
    }
}
